Method and apparatus for verifying block data in a blockchain

ABSTRACT

The present solution discloses example methods and systems for verifying block data. One example method includes identifying newly added data to be stored in a blockchain, and selecting a data node in a block to store the newly added data. A string is generated based on the newly added data, and then a verification value for the newly added data is developed from the string using a predetermined algorithm. A new verification value for the block is calculated based on the verification value of the newly added data and the original verification values of the unchanged data nodes in the block. The new verification value for the block can then be used to verify the data stored in the block is consistent with data stored in the rest of the blockchain.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of U.S. patent application Ser. No.16/441,543, filed on Jun. 14, 2019, which is a continuation of PCTApplication No. PCT/CN2017/116835, filed on Dec. 18, 2017, which claimspriority to Chinese Patent Application No. 201611215749.3, filed on Dec.26, 2016, and each application is hereby incorporated by reference inits entirety.

TECHNICAL FIELD

The present application relates to the field of computer communicationstechnologies, and in particular, to a method and an apparatus forverifying block data in a blockchain.

BACKGROUND

A blockchain technology is also referred to as a distributed ledgertechnology, and is a distributed Internet database technology. Theblockchain technology is decentralized, transparent, and trustable, andcannot be tampered with. Each piece of data stored in a blockchain isbroadcast and stored in each block in the blockchain. Therefore, fulland consistent data is stored in each block in the blockchain.

In practice, data stored in all blocks needs to keep consistent in ablockchain. A data verification method is usually used to verify whetherdata stored in all blocks is consistent.

Specifically, during block data verification, verification values of allblocks need to be determined, and the verification values of all theblocks need to be compared, to determine whether data stored in all theblocks in the blockchain is consistent.

Researches show that when a verification value of each block is to bedetermined, because an amount of data stored in the block is relativelylarge, when the verification value of the block is to be determined, alldata stored in the block needs to be calculated, to calculate theverification value of the block. However, as an amount of data stored inthe block increases, an amount of verification value calculationincreases, and consequently data verification efficiency decreases.

Therefore, how to improve block data verification efficiency becomes aproblem that needs to be alleviated in the art urgently.

The information disclosed in the background is merely intended toenhance an understanding of the general background of the presentapplication, and should not be considered as acknowledging or concedingthat the information constitutes the existing technology known to aperson skilled in the art.

SUMMARY

In view of this, implementations of the present application provide amethod and an apparatus for verifying block data, so as to alleviate aproblem of relatively low block data verification efficiency in theexisting technology.

An implementation of the present application provides a method forverifying block data, including: selecting, from a block including aplurality of data nodes, a data node configured to store newly addeddata; determining a verification value of the newly added data for thedata node, and calculating an update verification value of the data nodebased on the verification value of the newly added data; and obtaining averification value of the block based on the update verification valueof the data node and original verification values of other data nodesincluded in the block; where the verification value of the block is usedto verify whether data stored in the block is consistent with datastored in other blocks in a blockchain.

An implementation of the present application further provides anapparatus for verifying block data, including: a selection module,configured to select, from a block including a plurality of data nodes,a data node configured to store newly added data; a determining module,configured to determine a verification value of the newly added data forthe data node, and calculate an update verification value of the datanode based on the verification value of the newly added data; and aprocessing module, configured to obtain a verification value of theblock based on the update verification value of the data node andoriginal verification values of other data nodes included in the block;where the verification value of the block is used to verify whether datastored in the block is consistent with data stored in other blocks in ablockchain.

The previously described at least one technical solution used in theimplementations of the present application can achieve the followingbeneficial effects:

When the new data is added to the block, the update verification valueof the data node configured to store the newly added data is determinedby using the newly added data, so as to alleviate a problem in theexisting technology that much time is consumed because a verificationvalue is calculated by using all data in a block when new data is addedto the block. As such, when the verification value of the block that thenew data is added to is calculated, consumed time is irrelevant to anamount of data in the block, and time for calculating the verificationvalue is effectively shortened, improving block data verificationefficiency.

BRIEF DESCRIPTION OF DRAWINGS

The accompanying drawings described here are intended to provide afurther understanding of the present application, and constitute a partof the present application. The illustrative implementations of thepresent application and descriptions of the implementations of thepresent application are intended to describe the present application,and do not constitute limitations on the present application. In theaccompanying drawings:

FIG. 1 is a schematic flowchart illustrating a method for verifyingblock data, according to an implementation of the present application;

FIG. 2 is a schematic structural diagram illustrating a Merkle tree,according to an implementation of the present application;

FIG. 3 is a schematic flowchart of determining a verification value ofnewly added data, according to an implementation of the presentapplication;

FIG. 4 is a schematic flowchart of determining a verification value ofnewly added data, according to an implementation of the presentapplication;

FIG. 5 is a schematic structural diagram illustrating an apparatus forverifying block data, according to an implementation of the presentapplication; and

FIG. 6 is a flowchart illustrating an example of a computer-implementedmethod for verifying block data, according to an implementation of thepresent disclosure.

DESCRIPTION OF IMPLEMENTATIONS

To achieve objectives of the present application, the implementations ofthe present application provide a method and an apparatus for verifyingblock data. A data node configured to store newly added data is selectedfrom a block including a plurality of data nodes; a verification valueof the newly added data is determined for the data node, and an updateverification value of the data node is calculated based on theverification value of the newly added data; and a verification value ofthe block is obtained based on the update verification value of the datanode and original verification values of other data nodes included inthe block. The verification value of the block is used to verify whetherdata stored in the block is consistent with data stored in other blocksin a blockchain. Compared with the existing technology for processingall historical data, in the implementations of the present application,the newly added data of the block is mainly considered, and for theblock that the new data is added to, the verification value iscalculated by using an incremental method, so as to alleviate a problemin the existing technology that much time is consumed because averification value is calculated by using all data in a block when newdata is added to the block. As such, when the verification value of theblock that the new data is added to is calculated, consumed time isirrelevant to an amount of data in the block, and time for calculatingthe verification value is effectively shortened, improving block dataverification efficiency.

It is worthwhile to note that a predetermined algorithm used tocalculate a verification value that is described in the implementationsof the present application can be various verification algorithms, orcan be various irreversible algorithms, and a specific algorithm type isnot specifically limited in the implementations of the presentapplication.

For example, a needed verification value can be calculated by using ahash algorithm. The hash algorithm can also be referred to as a hashfunction. The hash function is a unidirectional cryptographic system, inother words, the hash function is an irreversible mapping from plaintextto ciphertext, in other words, the function includes only an encryptionprocess and does not include a decryption process. In addition, the hashfunction can obtain an output of a fixed length after changing an inputof any length. A typical hash algorithm includes MD2, MD4, MD5, SHA-1,etc.

A person skilled in the art should understand that the hash algorithmmentioned in the specification of the implementations of the presentapplication is merely an example, and does not constitute a limitationon the present disclosure. A person skilled in the art can use otheralgorithms used for verification based on actual applications and needs.This is not specifically limited here.

To make the objectives, technical solutions, and advantages of thepresent application clearer, the following clearly and comprehensivelydescribes the technical solutions of the present application withreference to specific implementations of the present application andcorresponding accompanying drawings. Apparently, the describedimplementations are only some rather than all of the implementations ofthe present application. All other implementations obtained by a personof ordinary skill in the art based on the implementations of the presentapplication without creative efforts shall fall within the protectionscope of the present application.

The following describes in detail the technical solutions provided inthe implementations of the present application with reference to theaccompanying drawings.

FIG. 1 is a schematic flowchart illustrating a method for verifyingblock data, according to an implementation of the present application.The method for verifying block data includes the following steps.

Step S110: Select, from a block including a plurality of data nodes, adata node configured to store newly added data.

A blockchain is obtained by connecting several blocks by using a chaindata structure. Each block includes a plurality of data nodes. The datanodes included in the block can be constructed in a form of a Merkletree, in other words, each include a root node and a plurality of leafnodes.

In the Merkle tree structure, the data nodes included in the block areused as bottom leaf nodes in the Merkle tree structure, which are shownin FIG. 2.

It can be seen from FIG. 2 that in the Merkle tree structure, A, B, C,D, and E correspond to the data nodes in the block.

A person skilled in the art should understand that the Merkle tree isconstructed based on the data nodes in the block, and the depth of theMerkle tree can be determined as needed.

It is worthwhile to note that to ensure consistency between data storedin all blocks in the blockchain, Merkle trees constructed in all theblocks in the blockchain have a same depth, and quantities of data nodesincluded in all the blocks are also the same. In addition, it should befurther understood that the Merkle tree listed here is merely an examplefor description, and a person skilled in the art can use otherappropriate data construction forms. This is not specifically limitedhere.

For data to be stored (the data here can be referred to as newly addeddata), a block used to store the newly added data is first determined,and then a data node in the block that is configured to store the newlyadded data is determined.

Therefore, when the newly added data is received, block information usedto store the newly added data is first determined. The block informationincludes a block identifier and a data node identifier.

Specifically, data content corresponding to the newly added data iscalculated, to obtain the determined block information.

In this implementation of the present application, the data contentcorresponding to the newly added data can be determined based on a typeof the newly added data, or can be determined based on data included inthe newly added data. This is not specifically limited here.

For example, if the newly added data is text data, the data contentcorresponding to the newly added data can be understood as a contentdigest of the text data, or can be understood as the text data, and thedata content (for example, the content digest or the text data)corresponding to the newly added data can be calculated based on apredetermined algorithm, to obtain a calculation result. In this case,the block information is determined based on the calculation result.

For another example, if the newly added data is one piece of transactiondata, the transaction data can be calculated based on a predeterminedalgorithm, to obtain a calculation result. In this case, the blockinformation is determined based on the calculation result.

In the predetermined algorithm described in this implementation of thepresent application, for example, in a remainder calculation method, thedata content is converted into integer data, a quantity of blocksincluded in the blockchain is used as a divisor, and the integer data iscalculated by using the divisor, to obtain a quotient and a remainder.The quotient here can be considered as a block identifier, and theremainder can be considered as a data node identifier in the block.Alternatively, the quotient can be considered as the data nodeidentifier, and the remainder can be considered as the block identifier.

Certainly, to assign the newly added data to an appropriate block anddata node as needed, a person skilled in the art can also use othermethods for calculating the data content, for example, performing randomcalculation on the data content. This is not limited here.

Then, the blockchain is searched based on the block identifier for ablock corresponding to the block identifier, and a data nodecorresponding to the data node identifier is determined from the foundblock.

In a process of obtaining the blockchain, one block identifier isdetermined for each block. Therefore, when the block information isobtained, the blockchain can be searched based on the block identifierin the block information for the block corresponding to the blockidentifier.

Each block includes a plurality of data nodes, and one data nodeidentifier can be determined for each data node. Therefore, when theblock information is obtained, the data node corresponding to the datanode identifier can be determined from the found blockchain based on thedata node identifier in the block information.

Finally, the found data node is used as the data node configured tostore the newly added data.

Step S120: Determine a verification value of the newly added data forthe data node.

In this implementation of the present application, because data possiblyhas been stored in the data node before the newly added data is storedin the data node, and some of these data is possibly associated with thenewly added data, the data associated with the newly added data can bereferred to as associated data. Alternatively, the data stored in thedata node is possibly not associated with the newly added data, in otherwords, the data node does not include associated data associated withthe newly added data.

It is worthwhile to note that the association relationship described inthis implementation of the present application can be a relationshipgenerated because of a user account, a payment activity, a transactiontime, a transaction location, etc., for example, two pieces oftransaction data of one user. In this case, the two pieces oftransaction data are associated because of a same user account.Alternatively, the association relationship can be a relationshipgenerated because of a transaction behavior. For example, contentrecorded in one piece of transaction data is that a user A transfers 100yuan to a user B, and content recorded in the other piece of transactiondata is that the user B transfers 100 yuan to the user A. In this case,the two pieces of transaction data are associated because objects andmoney included in the transfer behavior are the same. Specific contentof the association relationship is not specifically limited here.

In addition, no data possibly has been stored in the data node beforethe newly added data is stored in the data node. In this case, it can beconsidered that the data node does not include associated dataassociated with the newly added data.

Therefore, determining the verification value of the newly added datacan include but is not limited to the following two cases:

Case 1: The data node does not include associated data associated withthe newly added data.

For determining the verification value of the newly added data,reference can be made to FIG. 3. FIG. 3 is a schematic flowchart ofdetermining a verification value of newly added data, according to animplementation of the present application.

S310. Determine a character string corresponding to the newly addeddata.

In this implementation of the present application, the character stringcorresponding to the newly added data can be determined by using anyappropriate technical methods of converting data into a characterstring, for example, by converting the newly added data into thecharacter string by using a corresponding transfer function. This is notspecifically limited here.

S320. Calculate the character string based on a predetermined algorithm,to obtain the verification value of the newly added data.

Specifically, the character string is calculated by using a hashalgorithm, to obtain a hash value of the newly added data, and use thehash value as the verification value of the newly added data.

A person skilled in the art should understand that the hash algorithmmentioned here is merely an example, and does not constitute alimitation on the present disclosure.

Case 2: The data node includes associated data associated with the newlyadded data.

For determining the verification value of the newly added data,reference can be made to FIG. 4. FIG. 4 is a schematic flowchart ofdetermining a verification value of newly added data, according to animplementation of the present application.

S410. Separately determine a first character string corresponding to theassociated data and a second character string corresponding to the newlyadded data.

Likewise, the first character string corresponding to the associateddata and the second character string corresponding to the newly addeddata can be determined by using any appropriate technical methods ofconverting data into a character string, for example, by converting thenewly added data into the character string by using a correspondingtransfer function. This is not specifically limited here.

S420. Sort the first character string and the second character string byusing a predetermined method.

It is worthwhile to note that the predetermined method can be determinedbased on an actual need, or can be determined based on an experimentalresult. A sorting method used in this implementation of the presentapplication is not limited. For example, the first character string andthe second character string are sequentially sorted, to combine thefirst character string and the second character string to obtain acharacter string group used for calculation. Whether the first characterstring is before the second character string or the second characterstring is before the first character string is not limited in thisimplementation of the present application. A person skilled in the artcan also use other sorting methods.

S430. Calculate a sorted character string based on a predeterminedalgorithm, to obtain the verification value of the newly added data.

Specifically, the sorted character string is calculated by using a hashalgorithm, to obtain a hash value of the newly added data, and use thehash value as the verification value of the newly added data.

Step S130: Calculate an update verification value of the data node basedon the verification value of the newly added data.

Specifically, an original verification value of the data node obtainedbefore the newly added data is stored; and the update verification valueof the data node is calculated based on the original verification valueand the verification value of the newly added data.

In this implementation of the present application, if other data hasbeen stored before the newly added data is stored in the data node, averification value is calculated for the data node when the other datais stored. The verification value can be referred to as an originalverification value for the newly added data.

For example, for a data node A, one verification value is calculatedeach time one piece of data is stored, in other words, the verificationvalue of the data node changes with data in the data node. Assume thatdata 11 and data 12 have been stored in the data node A before the newlyadded data is stored, a verification value a is calculated when the data11 is stored in the data node, and a can be referred to as an originalverification value when the data 12 is stored in the data node. In thiscase, a verification value b is calculated by using the originalverification value, and b can be referred to as an update verificationvalue.

Assume that the newly added data is data 13, a verification value c ofthe data 13 is obtained according to step S120. In this case, averification value, namely, the verification value b, of the data nodeobtained before the data 13 is stored needs to be determined, and theverification value b is referred to as an original verification value.The update verification value of the data node is calculated based on apredetermined algorithm by using the verification value c and theverification value b.

It is worthwhile to note that if no data has been stored in the datanode, and the newly added data is used as first data of the data node,the verification value of the newly added data can be considered as theverification value of the data node in this implementation of thepresent application.

Step S140: Obtain a verification value of the block based on the updateverification value of the data node and original verification values ofother data nodes included in the block.

In this implementation of the present application, a tree structurecorresponding to the plurality of data nodes included in the block isdetermined, and the original verification value of the other data nodesincluded in the block is determined; and the tree structure is traversedbased on the update verification value of the data node and the originalverification values of the other data nodes included in the block, toobtain a verification value of a root node of the tree structure, anduse the verification value of the root node as the verification value ofthe block.

Content shown in FIG. 2 is used as an example. Assume that no newlyadded data has been stored in the block shown in FIG. 2, a verificationvalue corresponding to the data node A shown in FIG. 2 is a, averification value corresponding to the data node B is b, a verificationvalue corresponding to the data node C is c, a verification valuecorresponding to the data node D is d, and a verification valuecorresponding to the data node E is e.

In this case, the newly added data needs to be stored in the data nodeA, and therefore the verification value a, the verification value b, theverification value c, the verification value d, and the verificationvalue e are referred to as original verification values.

After the newly added data is stored in the data node A, theverification value of the data node A changes. Assume that theverification value of the data node A changes from the verificationvalue a to a verification value g, the verification value g can bereferred to as an update verification value of the data node A.

In this case, a verification value of the block is calculated based on apredetermined algorithm by using the verification value g of the datanode A, the verification value b of the data node B, the verificationvalue c of the data node C, the verification value d of the data node D,and the verification value e of the data node E.

For example, the verification value of the block is calculated based onthe tree structure that is corresponding to the data node A, the datanode B, the data node C, the data node D, and the data node E and thatis shown in FIG. 2 and by using the verification value g of the datanode A, the verification value b of the data node B, the verificationvalue c of the data node C, the verification value d of the data node D,and the verification value e of the data node E.

After the verification value of the block is obtained, the verificationvalue can be compared with verification values of other blocks in ablockchain. If the two verification values are consistent, it indicatesthat data stored in the block is consistent with data stored in theother blocks, and the verification succeeds. If the two verificationvalues are inconsistent, it indicates that data stored in the block isinconsistent with data stored in the other blocks. For example, the datain the block possibly has been lost or tampered with, and theverification cannot succeed.

In this implementation of the present application, the verificationvalue of the block that changes with the newly added data is quicklydetermined by using an incremental calculation method, so as to shortentime for calculating the verification value, and improves systemcomputing performance.

According to the technical solutions provided in the implementations ofthe present application, a data node configured to store newly addeddata is selected from a block including a plurality of data nodes; averification value of the newly added data is determined for the datanode, and an update verification value of the data node is calculatedbased on the verification value of the newly added data; and averification value of the block is obtained based on the updateverification value of the data node and original verification values ofother data nodes included in the block. The verification value of theblock is used to verify whether data stored in the block is consistentwith data stored in other blocks in a blockchain. Compared with theexisting technology for processing all historical data, in theimplementations of the present application, the newly added data of theblock is mainly considered, and for the block that the new data is addedto, the verification value is calculated by using an incremental method,so as to alleviate a problem in the existing technology that much timeis consumed because a verification value is calculated by using all datain a block when new data is added to the block. As such, when theverification value of the block that the new data is added to iscalculated, consumed time is irrelevant to an amount of data in theblock, and time for calculating the verification value is effectivelyshortened, improving block data verification efficiency.

In addition, if original data that is not processed is tampered with,although the tampering is not found when the verification value of thenewly added data is calculated in the implementations of the presentapplication, the data-tampering can be surely found when data update isperformed in each block of the blockchain because of structure andproperties of the blockchain. Therefore, final block data verificationis not affected.

FIG. 5 is a schematic structural diagram illustrating an apparatus forverifying block data, according to an implementation of the presentapplication. The apparatus for verifying block data includes a selectionmodule 510, a determining module 520, and a processing module 530.

The selection module 510 is configured to select, from a block includinga plurality of data nodes, a data node configured to store newly addeddata.

The determining module 520 is configured to determine a verificationvalue of the newly added data for the data node, and calculate an updateverification value of the data node based on the verification value ofthe newly added data.

The processing module 530 is configured to obtain a verification valueof the block based on the update verification value of the data node andoriginal verification values of other data nodes included in the block.

The verification value of the block is used to verify whether datastored in the block is consistent with data stored in other blocks in ablockchain.

In another implementation of the present application, that the selectionmodule 510 selects, from a block including a plurality of data nodes, adata node configured to store newly added data includes the following:when the newly added data is received, determining block informationused to store the newly added data, where the block information includesa block identifier and a data node identifier; searching, based on theblock identifier, the blockchain for a block corresponding to the blockidentifier, and determining, from the found block, a data nodecorresponding to the data node identifier; and using the found data nodeas the data node configured to store the newly added data.

In another implementation of the present application, that the selectionmodule 510 determines block information used to store the newly addeddata includes the following: calculating data content corresponding tothe newly added data, to obtain the determined block information.

In another implementation of the present application, that thedetermining module 520 determines a verification value of the newlyadded data includes the following: when it is determined that the datanode does not include associated data of the newly added data,determining a character string corresponding to the newly added data;and calculating the character string based on a predetermined algorithm,to obtain the verification value of the newly added data.

In another implementation of the present application, that thedetermining module 520 determines a verification value of the newlyadded data includes the following: when it is determined that the datanode includes associated data of the newly added data, separatelydetermining a first character string corresponding to the associateddata and a second character string corresponding to the newly addeddata; sorting the first character string and the second character stringby using a predetermined method; and calculating a sorted characterstring based on a predetermined algorithm, to obtain the verificationvalue of the newly added data.

In another implementation of the present application, that thedetermining module 520 calculates an update verification value of thedata node based on the verification value of the newly added dataincludes the following: determining an original verification value ofthe data node obtained before the newly added data is stored; andcalculating the update verification value of the data node based on theoriginal verification value and the verification value of the newlyadded data.

In another implementation of the present application, that theprocessing module 530 obtains a verification value of the block based onthe update verification value of the data node and original verificationvalues of other data nodes included in the block includes the following:determining a tree structure corresponding to the plurality of datanodes included in the block, and determining the original verificationvalues of the other data nodes included in the block; and traversing thetree structure based on the update verification value of the data nodeand the original verification values of the other data nodes included inthe block, to obtain a verification value of a root node of the treestructure, and use the verification value of the root node as theverification value of the block.

It is worthwhile to note that the apparatus for verifying block datadescribed in this implementation of the present application can beimplemented by using software, or can be implemented by using hardware.This is not specifically limited here. According to the apparatus forverifying block data, for the block that the new data is added to, theverification value is calculated by using an incremental method, so asto alleviate a problem in the existing technology that much time isconsumed because a verification value is calculated by using all data ina block when new data is added to the block. As such, when theverification value of the block that the new data is added to iscalculated, consumed time is irrelevant to an amount of data in theblock, and time for calculating the verification value is effectivelyshortened, improving block data verification efficiency.

In the 1990s, improvement of a technology can be clearly distinguishedbetween hardware improvement (for example, improvement on a circuitstructure such as a diode, a transistor, or a switch) and softwareimprovement (improvement on a method procedure). However, with thedevelopment of technologies, improvement of many method procedures canbe considered as direct improvement of a hardware circuit structure.Designers almost all program an improved method procedure to a hardwarecircuit, to obtain a corresponding hardware circuit structure.Therefore, it cannot be said that improvement of a method procedurecannot be implemented by using a hardware entity module. For example, aprogrammable logic device (PLD) (for example, a field programmable gatearray (FPGA)) is such an integrated circuit. A logical function of theprogrammable logic device is determined by component programmingexecuted by a user. The designers perform voluntary programming to“integrate” a digital system into a single PLD without requiring a chipmanufacturer to design and produce a dedicated integrated circuit chip.In addition, instead of manually producing an integrated circuit chip,the programming is mostly implemented by “logic compiler” software,which is similar to a software compiler used during program development.Original code before compiling is also written in a specific programminglanguage, which is referred to as a hardware description language (HDL),and there is more than one type of HDL, such as ABEL (Advanced BooleanExpression Language), AHDL (Altera Hardware Description Language),Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL(Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, andRHDL (Ruby Hardware Description Language), etc. Currently, VHDL(Very-High-Speed Integrated Circuit Hardware Description Language) andVerilog are most commonly used. A person skilled in the art should alsounderstand that a method procedure only needs to be logicallyprogrammed, and programmed to the integrated circuit by using theprevious hardware description languages so that a hardware circuit thatimplements the logical method procedure can be easily obtained.

A controller can be implemented by using any appropriate method. Forexample, the controller can be a microprocessor or a processor, or acomputer-readable medium, a logic gate, a switch, anapplication-specific integrated circuit (ASIC), a programmable logiccontroller, or an embedded microprocessor that stores computer readableprogram code (such as software or firmware) that can be executed by themicroprocessor or the processor. Examples of the controller include butare not limited to the following microprocessors: ARC 625D, AtmelAT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memorycontroller can also be implemented as a part of the control logic of thememory. A person skilled in the art also knows that a controller can beimplemented by using pure computer-readable program code, and the stepsin the method can be logically programmed to enable the controller tofurther implement same functions in forms of a logic gate, a switch, anapplication-specific integrated circuit, a programmable logiccontroller, an embedded microcontroller, etc. Therefore, the controllercan be considered as a hardware component, and an apparatus that isincluded in the controller and that is configured to implement variousfunctions can also be considered as a structure in the hardwarecomponent. Alternatively, an apparatus configured to implement variousfunctions can be considered as both a software module for implementingthe method and a structure in the hardware component.

The system, apparatus, module, or unit described in the describedimplementations can be implemented by a computer chip or an entity, orimplemented by a product with a certain function. A typicalimplementation device is a computer. The computer can be, for example, apersonal computer, a laptop computer, a cellular phone, a camera phone,a smartphone, a personal digital assistant, a media player, a navigationdevice, an email device, a game console, a tablet computer, or awearable device, or a combination of any of these devices.

For ease of description, the described apparatus is described bydividing functions into various units. Certainly, when the presentapplication is implemented, the functions of the units can beimplemented in one or more pieces of software and/or hardware.

A person skilled in the art should understand that the implementationsof the present disclosure can be provided as a method, a system, or acomputer program product. Therefore, the present disclosure can use aform of hardware only implementations, software only implementations, orimplementations with a combination of software and hardware. Inaddition, the present disclosure can use a form of a computer programproduct that is implemented on one or more computer-usable storage media(including but not limited to a disk memory, a CD-ROM, and an opticalmemory) that include computer-usable program code.

The present disclosure is described with reference to the flowchartsand/or block diagrams of the method, the device (system), and thecomputer program product according to the implementations of the presentdisclosure. It should be understood that computer program instructionscan be used to implement each process and/or each block in theflowcharts and/or the block diagrams and a combination of a processand/or a block in the flowcharts and/or the block diagrams. Thesecomputer program instructions can be provided for a general-purposecomputer, a dedicated computer, an embedded processor, or a processor ofany other programmable data processing device to generate a machine sothat the instructions executed by a computer or a processor of any otherprogrammable data processing device generate an apparatus forimplementing a specific function in one or more processes in theflowcharts or in one or more blocks in the block diagrams.

These computer program instructions can be stored in a computer readablememory that can instruct the computer or any other programmable dataprocessing device to work in a specific method, so that the instructionsstored in the computer readable memory generate an artifact thatincludes an instruction apparatus. The instruction apparatus implementsa specific function in one or more processes in the flowcharts and/or inone or more blocks in the block diagrams.

These computer program instructions can be loaded to a computer or otherprogrammable data processing devices, so that a series of operations andsteps are performed on the computer or the other programmable devices,generating computer-implemented processing. Therefore, the instructionsexecuted on the computer or the other programmable devices provide stepsfor implementing a specific function in one or more processes in theflowcharts or in one or more blocks in the block diagrams.

In a typical configuration, the computing device includes one or moreprocessors (CPU), one or more input/output interfaces, one or morenetwork interfaces, and one or more memories.

The memory can include a non-persistent memory, a random access memory(RAM) and/or a nonvolatile memory in a computer readable medium, forexample, a read-only memory (ROM) or a flash memory (flash RAM).

The computer readable medium includes persistent, non-persistent,movable, and unmovable media that can implement information storage byusing any method or technology. Information can be a computer readableinstruction, a data structure, a program module, or other data. Acomputer storage medium includes but is not limited to a phase-changerandom access memory (PRAM), a static random access memory (SRAM), adynamic random access memory (DRAM), a random access memory (RAM) ofanother type, a read-only memory (ROM), an electrically erasableprogrammable read-only memory (EEPROM), a flash memory or another memorytechnology, a compact disc read-only memory (CD-ROM), a digitalversatile disc (DVD) or another optical storage, a magnetic tape, amagnetic disk storage, another magnetic storage device, or any othernon-transmission media that can be used to store information that can beaccessed by the computing device. Based on the definition in the presentspecification, the computer readable medium does not include transitorycomputer readable medium (transitory media), for example, a modulateddata signal and carrier.

It is worthwhile to further note that the term “include”, “contain”, ortheir any other variant is intended to cover a non-exclusive inclusion,so that a process, a method, merchandise, or a device that includes alist of elements not only includes those elements but also includesother elements which are not expressly listed, or further includeselements inherent to such process, method, merchandise, or device. Anelement preceded by “includes a . . . ” does not, without moreconstraints, preclude the existence of additional identical elements inthe process, method, merchandise, or device that includes the element.

A person skilled in the art should understand that the implementationsof the present application can be provided as a method, a system, or acomputer program product. Therefore, the present application can use aform of hardware only implementations, software only implementations, orimplementations with a combination of software and hardware. Inaddition, the present application can use a form of a computer programproduct that is implemented on one or more computer-usable storage media(including but not limited to a disk memory, a CD-ROM, and an opticalmemory) that include computer-usable program code.

The previous descriptions are merely implementations of the presentapplication, and are not intended to limit the present application. Aperson skilled in the art can make various modifications and changes tothe present application. Any modification, equivalent replacement,improvement, etc. made within the spirit and principle of the presentapplication shall fall within the scope of the claims of the presentapplication.

As described herein, the present solution and description relates toimplementations for verifying block data in a blockchain. By calculatingan updated verification value from new data to be added to a data nodein a block, as opposed to the currently stored data in a block, andusing the original verification values from other data nodes, thecalculation time of the verification is shortened, and the processingpower required to perform the verification is lessened.

The proposed solution provides various technical advantages. In existingtechnology, a number of verification calculations increase as the amountof data in a block increases. In the present solution, the verificationvalue is determined using the newly added data (that is, not the fulldata of the block), such that the time required for calculation isindependent on the total amount of data in the block and is insteadbased on the new data being added to the block. The result is shortercalculation times, which allows a computer or computers to processlarger blocks more efficiently. The present solution improves theprocessing of the blockchain, allowing for faster block updates and moreefficient computation of verification values used to ensure the data ina block has not been lost or tampered with.

FIG. 6 is a flowchart illustrating an example of a computer-implementedmethod 600 for verifying block data, according to an implementation ofthe present disclosure. For clarity of presentation, the descriptionthat follows generally describes method 600 in the context of the otherfigures in this description. However, it will be understood that method600 can be performed, for example, by any system, environment, software,and hardware, or a combination of systems, environments, software, andhardware, as appropriate. In some implementations, various steps ofmethod 600 can be run in parallel, in combination, in loops, or in anyorder.

At 602, newly added data is identified to be stored in a blockchain. Thenewly added data may be text data, transaction data, quantity data, orany suitable alternative. From 602, method 600 proceeds to 604.

At 604, a data node configured to store newly added data is selectedfrom a block comprising a plurality of data nodes. The block may be ablock in a blockchain, which connects several blocks using a chain datastructure. Each block may be configured in the form of a Merkle tree,including a root node, non-leaf nodes, and leaf nodes. A data node maybe a leaf node in this configuration. The Merkle tree may have a depthas determined to be needed. For consistency, all of the Merkle trees ina given blockchain may have the same depth and quantity of data nodes.

In some instances, the data node may be selected using a blockidentifier and a data node identifier that are determined when receivingnewly added data. The block identifier and data node identifier may bedetermined based on the type of newly added data or on calculated datacontent of the newly added data. For example, the block identifier anddata node identifier may be determined based on a calculation resultobtained after executing an algorithm on the newly added data.

In one instance, the algorithm may be a remainder calculation method,wherein the newly added data is converted into integer data. In theremainder calculation method, a quantity of blocks included in ablockchain is used as a divisor, and the integer data is calculated byusing the divisor to obtain a quotient and a remainder. The quotient inthis instance may be the block identifier, and the remainder may be thedata node identifier. Alternatively, the quotient may be the data nodeidentifier, and the remainder may be the block identifier.

A data node configured to store the newly added data may be selected bysearching the blockchain for the block corresponding to the blockidentifier, where the block is a found block. Then, from the foundblock, a found data node corresponding to the data node identifier isdetermined, and the found data node is selected as the data nodeconfigured to store the newly added data. From 604, method 600 proceedsto 606.

At 606, a determination is made as to whether the selected data nodecomprises data associated with the newly added data. The data node mayhave previously had data stored in it, such that the previously storeddata may be associated with the newly added data. For example, thepreviously stored data may be a transaction from the same user accountas the newly added data. In another example, the previously stored datamay be associated with the newly added data because it relates totransactions of the same amount, or between the same users, among otherthings. If it is determined that the data node does not comprise orinclude data associated with the newly added data, then method 600proceeds to method 608. Otherwise, method 600 proceeds to 612 inresponse to determining that the data node comprises data associatedwith the newly added data.

At 608, a first character string corresponding to the newly added datais generated. This can be accomplished or performed using any suitablemethod of converting data into a character string. For example, acorresponding transfer function may be used. From 608, method 600proceeds to 610.

At 610, a first verification value of the newly added data for the datanode is determined or calculated by executing a predetermined algorithmon the first character string. The predetermined algorithm can be one ora combination of various suitable algorithms, including irreversiblealgorithms. For example, a verification value can be calculated using ahash algorithm (also known as a hash function). A hash function may be aunidirectional cryptographic system, resulting in an irreversiblemapping from plaintext to ciphertext. A hash function can produce anoutput of fixed length for an input of arbitrary length. Hash functionsmay include MD2, MD4, MD5, SHA-1, among others. From 610, method 600proceeds to 618.

Returning to 606, method 600 proceeds to 612 when it is determined thatthe selected data node comprises data associated with the newly addeddata. At 612, a second character string corresponding to the newly addeddata is generated, while a third character string corresponding to theassociated data is separately generated. The second and third characterstrings are determined using any suitable method of converting data intoa character string, including the same or different functions from eachother or as described in generating the first character string. From612, method 600 proceeds to 614.

At 614, a sorted character string is obtained by sorting the secondcharacter string and the third character string using a predeterminedmethod to obtain a character string group. The predetermined method maybe any suitable method for sorting character strings into characterstring groups. For example, the predetermined method may be a sequentialsorting, such as placing the second character string in front of thethird character string or vice versa. From 614, method 600 proceeds to616.

At 616, a first verification value of the newly added data for theselected data node is determined by executing a predetermined algorithmon the sorted character string. The predetermined algorithm and itsapplication may be similar or different to the algorithms described withregard to operations performed at 610. From 616, method 600 proceeds to618.

At 618, an updated second verification value of the selected data nodeis calculated based on the value of the newly added data. The updatedsecond verification value may be calculated by determining an originalsecond verification value for the selected data node prior to storingthe newly added data, and calculating the updated second verificationvalue of the selected data node based on the original secondverification value and the first verification value of the newly addeddata (for example, determined at either 616 or 610). From 618, method600 proceeds to 620.

At 620, a third verification value of the block is determined based onthe updated second verification value of the selected data node andoriginal second verification values of the other data nodes in theblock. The third verification value of the block is used to verifywhether data stored in the block is consistent with the data stored inother blocks in a blockchain. In one instance, the block may contain atree structure with a root node, non-leaf nodes, and leaf nodescorresponding to a plurality of data nodes. In this instance, theupdated second verification value of the selected data node and theoriginal second verification values of the other data nodes in the blockare calculated to obtain a third verification value of the root node,which is used as the third verification value of the block.

The third verification value of the block may then be compared with theverification values of other blocks in a blockchain. If the verificationvalues are consistent, the consistency indicates that the stored data inthe block is consistent with the data stored in the other blocks, andthe verification is determined to succeed. If the third verificationvalues between blocks are inconsistent, the inconsistency indicates thatdata stored in the block has possibly been lost or tampered with, andverification cannot succeed. After 620 method 600 stops.

Embodiments and the operations described in this specification can beimplemented in digital electronic circuitry, or in computer software,firmware, or hardware, including the structures disclosed in thisspecification or in combinations of one or more of them. The operationscan be implemented as operations performed by a data processingapparatus on data stored on one or more computer-readable storagedevices or received from other sources. A data processing apparatus,computer, or computing device may encompass apparatus, devices, andmachines for processing data, including by way of example a programmableprocessor, a computer, a system on a chip, or multiple ones, orcombinations, of the foregoing. The apparatus can include specialpurpose logic circuitry, for example, a central processing unit (CPU), afield programmable gate array (FPGA) or an application-specificintegrated circuit (ASIC). The apparatus can also include code thatcreates an execution environment for the computer program in question,for example, code that constitutes processor firmware, a protocol stack,a database management system, an operating system (for example anoperating system or a combination of operating systems), across-platform runtime environment, a virtual machine, or a combinationof one or more of them. The apparatus and execution environment canrealize various different computing model infrastructures, such as webservices, distributed computing and grid computing infrastructures.

A computer program (also known, for example, as a program, software,software application, software module, software unit, script, or code)can be written in any form of programming language, including compiledor interpreted languages, declarative or procedural languages, and itcan be deployed in any form, including as a stand-alone program or as amodule, component, subroutine, object, or other unit suitable for use ina computing environment. A program can be stored in a portion of a filethat holds other programs or data (for example, one or more scriptsstored in a markup language document), in a single file dedicated to theprogram in question, or in multiple coordinated files (for example,files that store one or more modules, sub-programs, or portions ofcode). A computer program can be executed on one computer or on multiplecomputers that are located at one site or distributed across multiplesites and interconnected by a communication network.

Processors for execution of a computer program include, by way ofexample, both general- and special-purpose microprocessors, and any oneor more processors of any kind of digital computer. Generally, aprocessor will receive instructions and data from a read-only memory ora random-access memory or both. The essential elements of a computer area processor for performing actions in accordance with instructions andone or more memory devices for storing instructions and data. Generally,a computer will also include, or be operatively coupled to receive datafrom or transfer data to, or both, one or more mass storage devices forstoring data. A computer can be embedded in another device, for example,a mobile device, a personal digital assistant (PDA), a game console, aGlobal Positioning System (GPS) receiver, or a portable storage device.Devices suitable for storing computer program instructions and datainclude non-volatile memory, media and memory devices, including, by wayof example, semiconductor memory devices, magnetic disks, andmagneto-optical disks. The processor and the memory can be supplementedby, or incorporated in, special-purpose logic circuitry.

Mobile devices can include handsets, user equipment (UE), mobiletelephones (for example, smartphones), tablets, wearable devices (forexample, smart watches and smart eyeglasses), implanted devices withinthe human body (for example, biosensors, cochlear implants), or othertypes of mobile devices. The mobile devices can communicate wirelessly(for example, using radio frequency (RF) signals) to variouscommunication networks (described below). The mobile devices can includesensors for determining characteristics of the mobile device's currentenvironment. The sensors can include cameras, microphones, proximitysensors, GPS sensors, motion sensors, accelerometers, ambient lightsensors, moisture sensors, gyroscopes, compasses, barometers,fingerprint sensors, facial recognition systems, RF sensors (forexample, Wi-Fi and cellular radios), thermal sensors, or other types ofsensors. For example, the cameras can include a forward- or rear-facingcamera with movable or fixed lenses, a flash, an image sensor, and animage processor. The camera can be a megapixel camera capable ofcapturing details for facial and/or iris recognition. The camera alongwith a data processor and authentication information stored in memory oraccessed remotely can form a facial recognition system. The facialrecognition system or one-or-more sensors, for example, microphones,motion sensors, accelerometers, GPS sensors, or RF sensors, can be usedfor user authentication.

To provide for interaction with a user, embodiments can be implementedon a computer having a display device and an input device, for example,a liquid crystal display (LCD) or organic light-emitting diode(OLED)/virtual-reality (VR)/augmented-reality (AR) display fordisplaying information to the user and a touchscreen, keyboard, and apointing device by which the user can provide input to the computer.Other kinds of devices can be used to provide for interaction with auser as well; for example, feedback provided to the user can be any formof sensory feedback, for example, visual feedback, auditory feedback, ortactile feedback; and input from the user can be received in any form,including acoustic, speech, or tactile input. In addition, a computercan interact with a user by sending documents to and receiving documentsfrom a device that is used by the user; for example, by sending webpages to a web browser on a user's client device in response to requestsreceived from the web browser.

Embodiments can be implemented using computing devices interconnected byany form or medium of wireline or wireless digital data communication(or combination thereof), for example, a communication network. Examplesof interconnected devices are a client and a server generally remotefrom each other that typically interact through a communication network.A client, for example, a mobile device, can carry out transactionsitself, with a server, or through a server, for example, performing buy,sell, pay, give, send, or loan transactions, or authorizing the same.Such transactions may be in real time such that an action and a responseare temporally proximate; for example an individual perceives the actionand the response occurring substantially simultaneously, the timedifference for a response following the individual's action is less than1 millisecond (ms) or less than 1 second (s), or the response is withoutintentional delay taking into account processing limitations of thesystem.

Examples of communication networks include a local area network (LAN), aradio access network (RAN), a metropolitan area network (MAN), and awide area network (WAN). The communication network can include all or aportion of the Internet, another communication network, or a combinationof communication networks. Information can be transmitted on thecommunication network according to various protocols and standards,including Long Term Evolution (LTE), 5G, IEEE 802, Internet Protocol(IP), or other protocols or combinations of protocols. The communicationnetwork can transmit voice, video, biometric, or authentication data, orother information between the connected computing devices.

Features described as separate implementations may be implemented, incombination, in a single implementation, while features described as asingle implementation may be implemented in multiple implementations,separately, or in any suitable sub-combination. Operations described andclaimed in a particular order should not be understood as requiring thatthe particular order, nor that all illustrated operations must beperformed (some operations can be optional). As appropriate,multitasking or parallel-processing (or a combination of multitaskingand parallel-processing) can be performed.

What is claimed is:
 1. A computer-implemented method for verifying blockdata, the computer-implemented method comprising: selecting, from ablock comprising a plurality of data nodes, a data node configured tostore newly added data; determining a first verification value of thenewly added data; determining, prior to storing the newly added data inthe selected data node, an original second verification value of theselected data node; calculating an updated second verification value ofthe selected data node based on the first verification value of thenewly added data and the original second verification value of theselected data node; and determining a third verification value of theblock based on the updated second verification value of the selecteddata node and respective original second verification values of otherdata nodes of the block, wherein the third verification value of theblock is used to verify whether data stored in the block is consistentwith data stored in other blocks in a blockchain.
 2. Thecomputer-implemented method of claim 1, wherein selecting the data nodecomprises: in response to receiving the newly added data, determining ablock identifier and a data node identifier, wherein the blockidentifier and the data node identifier are used to store the newlyadded data; searching, based on the block identifier, the blockchain fora block corresponding to the block identifier, wherein results of thesearch comprise a found block; determining, from the found block and thedata node identifier, a found data node corresponding to the data nodeidentifier; and selecting the found data node as the data nodeconfigured to store the newly added data.
 3. The computer-implementedmethod of claim 2, wherein determining the block identifier and datanode identifier comprises: calculating data content corresponding to thenewly added data to obtain the block identifier and data nodeidentifier.
 4. The computer-implemented method of claim 1, wherein:determining the first verification value of the newly added datacomprises executing an encryption algorithm; and the first verificationvalue comprises an encrypted value of the newly added data.
 5. Thecomputer-implemented method of claim 4, wherein the encryption algorithmcomprises a hash algorithm and the encrypted value comprises a hashvalue of the newly added data.
 6. The computer-implemented method ofclaim 1, wherein determining the first verification value of the newlyadded data further comprises: determining that the selected data nodecomprises data associated with the newly added data; and in response:separately generating a second character string corresponding to thenewly added data and a third character string corresponding to the dataassociated with the newly added data; obtaining a sorted characterstring by sorting the second character string and the third characterstring using a predetermined method; and determining a firstverification value of the newly added data for the data node byexecuting a predetermined algorithm on the sorted character string. 7.The computer-implemented method of claim 6, wherein the sorted characterstring comprises a character string group included in the firstverification value of the newly added data.
 8. The computer-implementedmethod of claim 1, wherein determining the third verification valuecomprises: determining a tree structure corresponding to the pluralityof data nodes comprised in the block; determining the original secondverification values of the other data nodes comprised in the block;traversing the tree structure based on the updated second verificationvalue of the selected data node and the original second verificationvalues of the other data nodes comprised in the block, to obtain a thirdverification value of a root node of the tree structure; and using thethird verification value of the root node as the third verificationvalue of the block.
 9. A non-transitory, computer-readable mediumstoring one or more instructions executable by a computer system toperform operations comprising: selecting, from a block comprising aplurality of data nodes, a data node configured to store newly addeddata; determining a first verification value of the newly added data;determining, prior to storing the newly added data in the selected datanode, an original second verification value of the selected data node;calculating an updated second verification value of the selected datanode based on the first verification value of the newly added data andthe original second verification value of the selected data node; anddetermining a third verification value of the block based on the updatedsecond verification value of the selected data node and respectiveoriginal second verification values of other data nodes of the block,wherein the third verification value of the block is used to verifywhether data stored in the block is consistent with data stored in otherblocks in a blockchain.
 10. The computer-readable medium of claim 9,wherein selecting the data node comprises: in response to receiving thenewly added data, determining a block identifier and a data nodeidentifier, wherein the block identifier and the data node identifierare used to store the newly added data; searching, based on the blockidentifier, the blockchain for a block corresponding to the blockidentifier, wherein results of the search comprise a found block;determining, from the found block and the data node identifier, a founddata node corresponding to the data node identifier; and selecting thefound data node as the data node configured to store the newly addeddata.
 11. The computer-readable medium of claim 10, wherein determiningthe block identifier and data node identifier comprises: calculatingdata content corresponding to the newly added data to obtain the blockidentifier and data node identifier.
 12. The computer-readable medium ofclaim 9 wherein: determining the first verification value of the newlyadded data comprises executing an encryption algorithm; and the firstverification value comprises an encrypted value of the newly added data.13. The computer-readable medium of claim 12, wherein the encryptionalgorithm comprises a hash algorithm and the encrypted value comprises ahash value of the newly added data.
 14. The computer-readable medium ofclaim 9, wherein determining the first verification value of the newlyadded data further comprises: determining that the selected data nodecomprises data associated with the newly added data; and in response:separately generating a second character string corresponding to thenewly added data and a third character string corresponding to the dataassociated with the newly added data; obtaining a sorted characterstring by sorting the second character string and the third characterstring using a predetermined method; and determining a firstverification value of the newly added data for the data node byexecuting a predetermined algorithm on the sorted character string. 15.The computer-readable medium claim 14, wherein the sorted characterstring comprises a character string group included in the firstverification value of the newly added data.
 16. The computer-readablemedium of claim 9, wherein determining the third verification valuecomprises: determining a tree structure corresponding to the pluralityof data nodes comprised in the block; determining the original secondverification values of the other data nodes comprised in the block;traversing the tree structure based on the updated second verificationvalue of the selected data node and the original second verificationvalues of the other data nodes comprised in the block, to obtain a thirdverification value of a root node of the tree structure; and using thethird verification value of the root node as the third verificationvalue of the block.
 17. A computer-implemented system, comprising: oneor more computers; and one or more computer memory devices interoperablycoupled with the one or more computers and having tangible,non-transitory, machine-readable media storing one or more instructionsthat, when executed by the one or more computers, perform one or moreoperations comprising: selecting, from a block comprising a plurality ofdata nodes, a data node configured to store newly added data;determining a first verification value of the newly added data;determining, prior to storing the newly added data in the selected datanode, an original second verification value of the selected data node;calculating an updated second verification value of the selected datanode based on the first verification value of the newly added data andthe original second verification value of the selected data node; anddetermining a third verification value of the block based on the updatedsecond verification value of the selected data node and respectiveoriginal second verification values of other data nodes of the block,wherein the third verification value of the block is used to verifywhether data stored in the block is consistent with data stored in otherblocks in a blockchain.
 18. The computer-implemented system of claim 17,wherein selecting the data node comprises: in response to receiving thenewly added data, determining a block identifier and a data nodeidentifier, wherein the block identifier and the data node identifierare used to store the newly added data; searching, based on the blockidentifier, the blockchain for a block corresponding to the blockidentifier, wherein results of the search comprise a found block;determining, from the found block and the data node identifier, a founddata node corresponding to the data node identifier; and selecting thefound data node as the data node configured to store the newly addeddata.
 19. The computer-implemented system of claim 17, wherein:determining the first verification value of the newly added datacomprises executing an encryption algorithm; and the first verificationvalue comprises an encrypted value of the newly added data.
 20. Thecomputer-implemented system of claim 17, wherein determining the firstverification value of the newly added data further comprises:determining that the selected data node comprises data associated withthe newly added data; and in response: separately generating a secondcharacter string corresponding to the newly added data and a thirdcharacter string corresponding to the data associated with the newlyadded data; obtaining a sorted character string by sorting the secondcharacter string and the third character string using a predeterminedmethod; and determining a first verification value of the newly addeddata for the data node by executing a predetermined algorithm on thesorted character string.